// 状态码
// author: Xavier
package result

// Codes 定义状态
type Codes struct {
	SUCCESS                    uint
	FAILED                     uint
	NOAUTH                     uint
	AUTHFORMATERROR            uint
	MissingLoginParameter      uint
	VerificationCodeHasExpired uint
	CAPTCHAERROR               uint
	PASSWORDERROR              uint
	STATUSISENABLE             uint
	INVALIDTOKEN               uint
	Message                    map[uint]string
}

// api 状态码
var ApiCode = &Codes{
	SUCCESS:                    200,
	FAILED:                     501,
	NOAUTH:                     403,
	AUTHFORMATERROR:            405,
	INVALIDTOKEN:               406,
	MissingLoginParameter:      407,
	VerificationCodeHasExpired: 408,
	CAPTCHAERROR:               409,
	PASSWORDERROR:              410,
	STATUSISENABLE:             411,
}

// 状态信息
func init() {
	ApiCode.Message = map[uint]string{
		ApiCode.SUCCESS:                    "成功",
		ApiCode.FAILED:                     "失败",
		ApiCode.NOAUTH:                     "请求头中的Authorization为空",
		ApiCode.AUTHFORMATERROR:            "请求头中的Authorization格式错误",
		ApiCode.MissingLoginParameter:      "登录参数缺失",
		ApiCode.VerificationCodeHasExpired: "验证码已过期",
		ApiCode.CAPTCHAERROR:               "验证码错误",
		ApiCode.PASSWORDERROR:              "密码错误",
		ApiCode.STATUSISENABLE:             "账号已禁用",
		ApiCode.INVALIDTOKEN:               "无效的token",
	}
}

// 供外部调用
func (c *Codes) GetMessage(code uint) string {
	if msg, ok := c.Message[code]; ok {
		return msg
	}
	return "未知状态码"
}
